Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

경북대 FE_이정민_3주차 과제 Step2 #57

Open
wants to merge 14 commits into
base: userjmmm
Choose a base branch
from

Conversation

userjmmm
Copy link

안녕하세요 멘토님,
"Error, Loading Status 핸들링 하기"를 구현한 2단계 코드를 제출합니다!
감사합니다 :)

Copy link

@sjoleee sjoleee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다~ 리뷰 남깁니다

import { keyframes } from '@emotion/react';
import styled from '@emotion/styled';

const Loading: React.FC = () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서는 왜 React.FC를 사용하셨나요?
React.FC를 쓸때와 쓰지 않을때의 차이는 무엇인가요?

Comment on lines +38 to +40
isError: boolean;
errorCode?: string;
errorMessage?: string;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error?: { code?: string; message?: string }

error와 관련된 것들을 모아서 하나의 객체로 처리하면 어떨까요?

Comment on lines +12 to +16
if (axios.isAxiosError(error)) { // axios는 자동으로 JSON 변환해줌
const code = error.response?.status?.toString() || 'UNKNOWN_ERROR';
const description = error.response?.data?.description || '알 수 없는 오류가 발생했어요.';
throw Object.assign(new Error(), {code, description });
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굳이 이렇게 만들어주는 이유가 있을까요?
에러 객체에서 필요한 정보가 코드와 설명 이외에도 있으면 어떻게 대응하실 예정일까요?

const response = await fetchData('/api/v1/ranking/products', filters);
setFetchState({ isLoading: false, isError: false, data: response.products });
} catch (error) {
const axiosError = error as AxiosError;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

타입 단언이 좋은 선택일까요?
굳이 타입 단언을 하지 않고도 axiosError일때 아래 로직을 수행할 수 있을 것 같아요~

Comment on lines +82 to +90
{fetchState.isLoading ? (
<Loading />
) : fetchState.isError ? (
<ErrorMessage code= {fetchState.errorCode} message={fetchState.errorMessage || '데이터를 불러오는 중에 문제가 발생했습니다.'} />
) : fetchState.data && fetchState.data.length > 0 ? (
<GoodsRankingList goodsList={fetchState.data} />
) : (
<EmptyData />
)}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

삼항연산자를 중첩 사용하여 가독성이 좋지 않은 것 같아요. 조금 더 깔끔하게 표현해볼 수 있을까요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants